// pages/companyApprove1/companyApprove1.js

const app = getApp()
const pathUrl = app.globalData.pathUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proAry: ['企业验证', '发起公证', '活体检测', '签署完成'],
    agree:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    var orderNo = wx.getStorageSync('orderNo')
    var userId = wx.getStorageSync('userId')
    var telphone = wx.getStorageSync('telphone')
    that.setData({
      orderNo: orderNo,
      userId: userId,
      telphone:telphone,
    })
    this.getList03();
    this.getCorporateBankList();
  },
  getList03:function(){
    var that =this;
    var orderNo = that.data.orderNo;
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl03/list',
      method: 'GET',
      data: {
        query07: orderNo,
      },
      success: function (res) {
        console.log(res);
        var list =res.data.result.records[0]
        console.log(list)
        wx.setStorageSync("userId1", list.query24)
        that.setData({
          companyName: list.query12,
          code: list.query13,
          companyName1: list.query12,
          userId1:list.query24
          // bankCode: list.query20,
          // bankName: list.query20,
          // bankId: list.query20
        })
      },
      fail: function (res) { }
    });
  }, 
  agree: function (e) {
    console.log(e.detail.value)
    if (e.detail.value == '') {
      this.setData({
        isCheck: false
      });
    } else {
      this.setData({
        isCheck: true
      });
    }
  },
  goSub: function () {
    var that = this;

    if (!that.data.isCheck) {
      wx.showModal({
        title: '提示',
        content: '请再次同意并勾选协议',
        showCancel: false
      })
      return false;
    }
    wx.showToast({
      title: '提交信息',
    })
    var inAcctName = that.data.companyName;
    var businessLicenseId = that.data.code;
    var businessLicenseName = that.data.companyName1;
    var userId = that.data.userId1;
    var inAcctNo = that.data.bankCode;
    var inAcctBankName = that.data.bankName;
    var inAcctBankNo = that.data.bankId;
    var businessLicenseFileId = wx.getStorageSync('fileId3')
    var data = {
      userId: userId,
      inAcctName: inAcctName,
      businessLicenseId: businessLicenseId,
      businessLicenseName: businessLicenseName,
      inAcctNo: inAcctNo,
      inAcctBankName: inAcctBankName,
      inAcctBankNo: inAcctBankNo,
      businessLicenseFileId: businessLicenseFileId,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/doEnterpriseRealnameRequest',
      method: 'POST',
      data: data,
      success: function (res) {
        console.log(res)
        if(res.da.success){
          wx.showModal({
            title: '提示',
            content: '企业认证成功',
            showCancel: false,
            success(res){
              if(res.confirm){
                wx.navigateTo({
                  url: '/pages/companyValidation/companyValidation',
                })
              }
            }
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.message,
            showCancel: false,
            success(res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/index/index',
                })
              }
            }
          })
        }
        
        // wx.navigateTo({
        //   url: '../notificationbook/notificationbook',
        // })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function (res) { }
    });
  },
  getCorporateBankList: function () {
    var that = this;
    var orderNo = that.data.orderNo;
    wx.request({
      url: pathUrl + '/fxy/1/getCorporateBankList',
      data:{
        userId:'123'
      },
      method: 'POST',
      success: function (res) {
        console.log(res);
        console.log(JSON.parse(res.data.message).resultData.bankInfos)
        var bankInfo = JSON.parse(res.data.message).resultData.bankInfos;
        that.setData({
          array:bankInfo
        })
        // var list = res.data.result.records[0]
        // console.log(list)
        // that.setData({
        //   companyName: list.query12,
        //   code: list.query13,
        //   companyName1: list.query12,
        //   // bankCode: list.query20,
        //   // bankName: list.query20,
        //   // bankId: list.query20
        // })
      },
      fail: function (res) { }
    });
  }, 
  companyNameInput:function(e){
    this.setData({
      companyName: e.detail.value
    })
  },
  codeInput: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
  companyName1Input: function (e) {
    this.setData({
      companyName1: e.detail.value
    })
  },
  bankCodeInput: function (e) {
    this.setData({
      bankCode: e.detail.value
    })
  },
  bankNameInput: function (e) {
    this.setData({
      bankName: e.detail.value
    })
  },
  bankIdInput: function (e) {
    this.setData({
      bankId: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})